## Sudan / South Sudan Descriptive Statistics 
rm(list = ls())
library(dplyr)
df <- read.csv("data_sudan_aan25_militias_neg.csv")

x <- df |> select(inpp, Year, Month, Mil_vs_Reb_dm_lag, Mil_vs_Civ_lag, Mil_vs_Gov_lag, Mil_vs_Reb_oth_lag, 
                  Mil_vs_Mil_lag, duration_ln, gbrd_best_cumsum_lag, gbrd_best_lag, rebno_ct,
                  tslinpp, tslinpp2, tslinpp3)

d.n    <- apply(x, 2, function(x){ return(length(na.omit(x)))})
d.mean <- apply(x, 2, mean, na.rm = T)
d.sd  <- apply(x, 2, sd, na.rm = T)
d.min <- apply(x, 2, min, na.rm = T)
d.max <- apply(x, 2, max, na.rm = T)
d.p25 <- apply(x, 2, quantile, na.rm = T, probs = 0.25 )
d.p50 <- apply(x, 2, quantile, na.rm = T, probs = 0.50 )
d.p75 <- apply(x, 2, quantile, na.rm = T, probs = 0.75 )

# Output
output <- round(cbind(d.n, d.mean, d.sd, d.min, d.max, d.p25, d.p50, d.p75),2)


write.csv(output, "appendix_desc_sudan.csv", row.names = T)
